﻿#ifndef PST_THREEDSURFACEPLOTSIDEBARDATA_H
#define PST_THREEDSURFACEPLOTSIDEBARDATA_H

#include <QObject>
#include <QList>
#include <QDomNodeList>
#include <QDomElement>
#include <QDomText>
#include <QDomAttr>
#include "FieldGraphGenerator.h"
#include "TextFileParser.h"
#include "BaseModule/GlobalHelper.h"

namespace pst
{
    class TextFileParser;

    class ThreeDSurfacePlotSidebarData :public QObject
    {
        Q_OBJECT

    public:
        ThreeDSurfacePlotSidebarData(QObject* parent = nullptr) :QObject(parent) {}
        ~ThreeDSurfacePlotSidebarData() {}

        void setGraphName(const QString& graphName) { m_graphName = graphName; }
        QString getGraphName() const { return m_graphName; }

        void setIsGraphNameRenamed(bool isRenamed) { m_isGraphNameRenamed = isRenamed; };
        bool getIsGraphNameRenamed() { return m_isGraphNameRenamed; };

        void setTextFileParser(TextFileParser* textFileParser) { m_textFileParser = textFileParser; }
        TextFileParser* getTextFileParser() const { return m_textFileParser; }

        void setIsShowActor(bool isShowActor) { m_isShowActor = isShowActor; }
        bool getIsShowActor() const { return m_isShowActor; }

        void setFrequencyList(const QList<double>& frequencyList) { m_frequencyList = frequencyList; }
        QList<double> getFrequencyList() const { return m_frequencyList; }

        void setCurrentFrequencyIndex(int currentFrequencyIndex) { m_currentFrequencyIndex = currentFrequencyIndex; }
        int getCurrentFrequencyIndex() const { return m_currentFrequencyIndex; }

        void setCurrentValueGroupNameIndex(int index) { m_currentValueGroupNameIndex = index; }
        int getCurrentValueGroupNameIndex() const { return m_currentValueGroupNameIndex; }

        void setCurrentComponentIndex(int index) { m_currentComponentIndex = index; }
        int getCurrentComponentIndex() const { return m_currentComponentIndex; }

        void setValueGroupNameList(const QList<QString>& valueGroupNameList) { m_valueGroupNameList = valueGroupNameList; }
        QList<QString> getValueGroupNameList() const { return m_valueGroupNameList; }

        bool getIsLog() const { return m_isLog; }
        void setIsLog(bool isLog) { m_isLog = isLog; }

        bool getIsNormalize() const { return m_isNormalize; }
        void setIsNormalize(bool isNormalize) { m_isNormalize = isNormalize; }

        void setDataSource(const QString& dataSource) { m_dataSource = dataSource; };
        QString getDataSource() const { return m_dataSource; };

        void PrintSelf()
        {
            qInfo() << "m_graphName:" << m_graphName;
            qInfo() << "m_isGraphNameRenamed:" << m_isGraphNameRenamed;
            qInfo() << "m_isShowActor:" << m_isShowActor;
            qInfo() << "m_currentFrequencyIndex:" << m_currentFrequencyIndex;
            qInfo() << "m_frequencyList:" << m_frequencyList;
            qInfo() << "m_currentValueGroupNameIndex:" << m_currentValueGroupNameIndex;
            qInfo() << "m_currentComponentIndex:" << m_currentComponentIndex;
            qInfo() << "m_valueGroupNameList:" << m_valueGroupNameList;
            qInfo() << "m_isLog:" << m_isLog;
            qInfo() << "m_isNormalize:" << m_isNormalize;
            qInfo() << "m_dataSource:" << m_dataSource;
        }

                /// @brief 文件写出至工程文件
        QDomElement& writeToProjectFile(QDomDocument* doc, QDomElement* element, bool isdiso = false)
        {
            QDomElement _ThreeDSurfacePlotSidebarDataRoot = doc->createElement("ThreeDSurfacePlotSidebarData");

            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "GraphName", m_graphName);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsGraphNameRenamed", QString::number(m_isGraphNameRenamed));
            m_textFileParser->writeToProjectFile(doc, &_ThreeDSurfacePlotSidebarDataRoot, isdiso);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsShowActor", QString::number(m_isShowActor));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "CurrentFrequencyIndex", QString::number(m_currentFrequencyIndex));
            auto _frequencyListStr = GlobalHelperInstance->convertDoubleListToQString(m_frequencyList);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "FrequencyList", _frequencyListStr);
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "ValueGroupNameList", m_valueGroupNameList.join(';'));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "CurrentValueGroupNameIndex", QString::number(m_currentValueGroupNameIndex));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "CurrentComponentIndex", QString::number(m_currentComponentIndex));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsLog", QString::number(m_isLog));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "IsNormalized", QString::number(m_isNormalize));
            GlobalHelperInstance->createDomElement(doc, &_ThreeDSurfacePlotSidebarDataRoot, "DataSource", m_dataSource);

            element->appendChild(_ThreeDSurfacePlotSidebarDataRoot);

            return _ThreeDSurfacePlotSidebarDataRoot;
        }
        /// @brief 从工程文件读入数据
        void readFromProjectFile(QDomElement* element, bool isdiso = false)
        {
            auto _GraphNameNodeList = element->elementsByTagName("GraphName");
            m_graphName = _GraphNameNodeList.item(0).toElement().text();
            auto _IsGraphNameRenamedNodeList = element->elementsByTagName("IsGraphNameRenamed");
            m_isGraphNameRenamed = (bool)_IsGraphNameRenamedNodeList.item(0).toElement().text().toInt();
            m_textFileParser->readFromProjectFile(&element->elementsByTagName("TextFileParser"), isdiso);
            auto _IsShowActorNodeList = element->elementsByTagName("IsShowActor");
            m_isShowActor = (bool)_IsShowActorNodeList.item(0).toElement().text().toInt();
            auto _CurrentFrequencyIndexNodeList = element->elementsByTagName("CurrentFrequencyIndex");
            m_currentFrequencyIndex = (int)_CurrentFrequencyIndexNodeList.item(0).toElement().text().toDouble();
            auto _FrequencyListNodeList = element->elementsByTagName("FrequencyList");
            m_frequencyList = GlobalHelperInstance->convertStringToDoubleList(_FrequencyListNodeList.item(0).toElement().text());
            auto _ValueGroupNameListNodeList = element->elementsByTagName("ValueGroupNameList");
            m_valueGroupNameList = _ValueGroupNameListNodeList.item(0).toElement().text().split(';');
            auto _CurrentValueGroupNameIndexNodeList = element->elementsByTagName("CurrentValueGroupNameIndex");
            m_currentValueGroupNameIndex = (int)_CurrentValueGroupNameIndexNodeList.item(0).toElement().text().toDouble();
            auto _CurrentComponentIndexNodeList = element->elementsByTagName("CurrentComponentIndex");
            m_currentComponentIndex = (int)_CurrentComponentIndexNodeList.item(0).toElement().text().toDouble();
            auto _IsLogNodeList = element->elementsByTagName("IsLog");
            m_isLog = (bool)_IsLogNodeList.item(0).toElement().text().toInt();
            auto _IsNormalizedNodeList = element->elementsByTagName("IsNormalized");
            m_isNormalize = (bool)_IsNormalizedNodeList.item(0).toElement().text().toInt();
            auto _DataSourceNodeList = element->elementsByTagName("DataSource");
            m_dataSource = _DataSourceNodeList.item(0).toElement().text();
        }

    private:
        QString m_graphName = ""; //图名称
        bool m_isGraphNameRenamed = false;//是否有被手动重命名过
        TextFileParser* m_textFileParser = nullptr;
        bool m_isShowActor = true;
        double m_currentFrequencyIndex = 0.0;
        QList<double> m_frequencyList;
        //double m_currentFixedParam = 0.0;
        QList<QString> m_valueGroupNameList;
        int m_currentValueGroupNameIndex = 0;
        int m_currentComponentIndex = 0;
        bool m_isLog = false;
        bool m_isNormalize = false;
        QString m_dataSource = "";
    };
}
#endif
